package com.adcc.monitoragent.util;

import java.io.File;
import java.util.List;

import org.apache.commons.configuration.CompositeConfiguration;
import org.apache.commons.configuration.PropertiesConfiguration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 通用属性工具
 * 这里囊括所有属性，但是不初始化，只有默认值。初始化在程序启动时手动设置对应的值
 * 方便配置通用设置统一管理
 * @author charlie
 *
 */
public class ProtertiesUtil {
	/**
	 * 集群名
	 */
	private static String clusterName = "";
	/**
	 * 展现集群名称
	 */
	private static List<Object> showClusterNames;
	/**
	 * 关心的mq队列信息
	 */
	private static List<Object> interestMqMetrics;
	
	/**
	 * 接收端口
	 */
	private static int recivePort;
	/**
	 * 发送地址
	 */
	private static List<Object> sendUrls;
	/**
	 * 日志父目录
	 */
	private static String showLogPathParent;
	/**
	 * 日志文件名称
	 */
	private static List<Object> showLogPaths;
	/**
	 * 动态展现
	 */
	private static boolean showDynamic;
	private static String initNodeConfig;
	/**
	 * 操作系统ip
	 */
	private static String osIp = "127.0.0.1";
	//数据库参数
	private static List<Object> dbConnectString;
	private static String dbUsername;
	private static String dbPassword;
	//redis参数
	private static List<Object> redisConnectString;
	private static String redisUsername;
	private static String redisPassword;
	//mq参数
	private static List<Object> mqConnectString;//连接串
	private static List<Object> mqTestString;//收发测试串
	private static List<Object> mqClusterString;//集群串
	private static int maxMqQueueNumber = 500;
	private static String mqUsername;
	private static String mqPassword;
	//zookeeper参数
	private static List<Object> zookeeperConnectString;
	private static String zookeeperUsername;
	private static String zookeeperPassword;
	//mongodb参数
	private static List<Object> mongodbConnectString;
	private static String mongodbUsername;
	private static String mongodbPassword;
	private static CompositeConfiguration config;
	/**
	 * 监控时间间隔
	 */
	private static int timeInterval = 10;
	
	private final static Logger log = LoggerFactory.getLogger(ProtertiesUtil.class);

	
	public static void init() {
		try {
			String path = "conf/application.properties";
			File f = new File(path);
			config = new CompositeConfiguration();
			if(f.exists()) {
				
				PropertiesConfiguration pc = new PropertiesConfiguration();  
				pc.setEncoding("utf8");  
				pc.load(path);
				
				config.addConfiguration(pc);
				ProtertiesUtil.setClusterName(config.getString("clusterName"));
				ProtertiesUtil.setDbConnectString(config.getList("db.connectString"));
				ProtertiesUtil.setDbPassword(config.getString("db.password"));
				ProtertiesUtil.setDbUsername(config.getString("db.username"));
				ProtertiesUtil.setSendUrls(config.getList("sendUrls"));
				ProtertiesUtil.setMaxMqQueueNumber(config.getInt("maxMqQueueNumber", 500));
				ProtertiesUtil.setRecivePort(config.getInt("recivePort", 8522));
				ProtertiesUtil.setMongodbConnectString(config.getList("mongodb.connectString"));
				ProtertiesUtil.setMongodbPassword(config.getString("mongodb.password"));
				ProtertiesUtil.setMongodbUsername(config.getString("mongodb.username"));
				ProtertiesUtil.setMqConnectString(config.getList("mq.connectString"));
				ProtertiesUtil.setMqTestString(config.getList("mq.testString"));
				ProtertiesUtil.setMqClusterString(config.getList("mq.clusterString"));
				ProtertiesUtil.setMqPassword(config.getString("mq.password"));
				ProtertiesUtil.setMqUsername(config.getString("mq.username"));
				ProtertiesUtil.setOsIp(config.getString("os.ip"));
				ProtertiesUtil.setRedisConnectString(config.getList("redis.connectString"));
				ProtertiesUtil.setRedisPassword(config.getString("redis.password"));
				ProtertiesUtil.setRedisUsername(config.getString("redis.username"));
				ProtertiesUtil.setTimeInterval(config.getInt("timeInterval"));
				ProtertiesUtil.setZookeeperConnectString(config.getList("zookeeper.connectString"));
				ProtertiesUtil.setZookeeperPassword(config.getString("zookeeper.password"));
				ProtertiesUtil.setZookeeperUsername(config.getString("zookeeper.username"));
				ProtertiesUtil.setShowClusterNames(config.getList("showClusterNames"));
				ProtertiesUtil.setInterestMqMetrics(config.getList("interestMqMetrics"));
				ProtertiesUtil.setShowLogPaths(config.getList("showLogPaths"));
				ProtertiesUtil.setShowLogPathParent(config.getString("showLogPathParent"));
				ProtertiesUtil.setInitNodeConfig(config.getString("initNodeConfig"));
				ProtertiesUtil.setShowDynamic(config.getBoolean("showDynamic", false));
			}
		} catch (Exception e) {
			log.error("配置文件初始化失败" + e.getMessage());
		}
	}
	
	public static String getClusterName() {
		return clusterName;
	}
	public static void setClusterName(String clusterName) {
		ProtertiesUtil.clusterName = clusterName;
	}
	public static String getOsIp() {
		return osIp;
	}
	public static void setOsIp(String osIp) {
		ProtertiesUtil.osIp = osIp;
	}
	public static int getTimeInterval() {
		return timeInterval;
	}
	public static void setTimeInterval(int timeInterval) {
		ProtertiesUtil.timeInterval = timeInterval;
	}
	public static List<Object> getDbConnectString() {
		return dbConnectString;
	}
	public static void setDbConnectString(List<Object> dbConnectString) {
		ProtertiesUtil.dbConnectString = dbConnectString;
	}
	public static String getDbUsername() {
		return dbUsername;
	}
	public static void setDbUsername(String dbUsername) {
		ProtertiesUtil.dbUsername = dbUsername;
	}
	public static String getDbPassword() {
		return dbPassword;
	}
	public static void setDbPassword(String dbPassword) {
		ProtertiesUtil.dbPassword = dbPassword;
	}
	public static List<Object> getRedisConnectString() {
		return redisConnectString;
	}
	public static void setRedisConnectString(List<Object> redisConnectString) {
		ProtertiesUtil.redisConnectString = redisConnectString;
	}
	public static String getRedisUsername() {
		return redisUsername;
	}
	public static void setRedisUsername(String redisUsername) {
		ProtertiesUtil.redisUsername = redisUsername;
	}
	public static String getRedisPassword() {
		return redisPassword;
	}
	public static void setRedisPassword(String redisPassword) {
		ProtertiesUtil.redisPassword = redisPassword;
	}
	public static List<Object> getMqConnectString() {
		return mqConnectString;
	}
	public static void setMqConnectString(List<Object> mqConnectString) {
		ProtertiesUtil.mqConnectString = mqConnectString;
	}
	public static String getMqUsername() {
		return mqUsername;
	}
	public static void setMqUsername(String mqUsername) {
		ProtertiesUtil.mqUsername = mqUsername;
	}
	public static String getMqPassword() {
		return mqPassword;
	}
	public static void setMqPassword(String mqPassword) {
		ProtertiesUtil.mqPassword = mqPassword;
	}
	public static List<Object> getZookeeperConnectString() {
		return zookeeperConnectString;
	}
	public static void setZookeeperConnectString(List<Object> zookeeperConnectString) {
		ProtertiesUtil.zookeeperConnectString = zookeeperConnectString;
	}
	public static String getZookeeperUsername() {
		return zookeeperUsername;
	}
	public static void setZookeeperUsername(String zookeeperUsername) {
		ProtertiesUtil.zookeeperUsername = zookeeperUsername;
	}
	public static String getZookeeperPassword() {
		return zookeeperPassword;
	}
	public static void setZookeeperPassword(String zookeeperPassword) {
		ProtertiesUtil.zookeeperPassword = zookeeperPassword;
	}
	public static List<Object> getMongodbConnectString() {
		return mongodbConnectString;
	}
	public static void setMongodbConnectString(List<Object> mongodbConnectString) {
		ProtertiesUtil.mongodbConnectString = mongodbConnectString;
	}
	public static String getMongodbUsername() {
		return mongodbUsername;
	}
	public static void setMongodbUsername(String mongodbUsername) {
		ProtertiesUtil.mongodbUsername = mongodbUsername;
	}
	public static String getMongodbPassword() {
		return mongodbPassword;
	}
	public static void setMongodbPassword(String mongodbPassword) {
		ProtertiesUtil.mongodbPassword = mongodbPassword;
	}

	public static List<Object> getShowClusterNames() {
		return showClusterNames;
	}

	public static void setShowClusterNames(List<Object> showClusterNames) {
		ProtertiesUtil.showClusterNames = showClusterNames;
	}

	public static List<Object> getInterestMqMetrics() {
		return interestMqMetrics;
	}

	public static void setInterestMqMetrics(List<Object> interestMqMetrics) {
		ProtertiesUtil.interestMqMetrics = interestMqMetrics;
	}

	public static List<Object> getSendUrls() {
		return sendUrls;
	}

	public static void setSendUrls(List<Object> reciveUrls) {
		ProtertiesUtil.sendUrls = reciveUrls;
	}

	public static int getRecivePort() {
		return recivePort;
	}

	public static void setRecivePort(int recivePort) {
		ProtertiesUtil.recivePort = recivePort;
	}

	public static List<Object> getShowLogPaths() {
		return showLogPaths;
	}

	public static void setShowLogPaths(List<Object> showLogPaths) {
		ProtertiesUtil.showLogPaths = showLogPaths;
	}

	public static CompositeConfiguration getConfig() {
		return config;
	}

	public static String getShowLogPathParent() {
		return showLogPathParent;
	}

	public static void setShowLogPathParent(String showLogPathParent) {
		ProtertiesUtil.showLogPathParent = showLogPathParent;
	}

	public static int getMaxMqQueueNumber() {
		return maxMqQueueNumber;
	}

	public static void setMaxMqQueueNumber(int maxMqQueueNumber) {
		ProtertiesUtil.maxMqQueueNumber = maxMqQueueNumber;
	}

	public static List<Object> getMqTestString() {
		return mqTestString;
	}

	public static void setMqTestString(List<Object> mqTestString) {
		ProtertiesUtil.mqTestString = mqTestString;
	}

	public static List<Object> getMqClusterString() {
		return mqClusterString;
	}

	public static void setMqClusterString(List<Object> mqClusterString) {
		ProtertiesUtil.mqClusterString = mqClusterString;
	}

	public static boolean isShowDynamic() {
		return showDynamic;
	}

	public static void setShowDynamic(boolean showDynamic) {
		ProtertiesUtil.showDynamic = showDynamic;
	}

	public static String getInitNodeConfig() {
		return initNodeConfig;
	}

	public static void setInitNodeConfig(String initNodeConfig) {
		ProtertiesUtil.initNodeConfig = initNodeConfig;
	}
	
}
